<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:p="http://primefaces.org/ui">


    <ui:define name="content">

        <h:form>



            <p:panel header="Error Detection" >
                <f:facet name="header" >
                    <h:outputLabel value="Error Detection" ></h:outputLabel>
                    <h:panelGrid columns="2">
                        <h:outputLabel value="From Date"/>                             
                        <p:calendar value="#{storeErrorChecking.fromDate}" pattern="dd MM yyyy" placeholder="From Date" ></p:calendar>
                        <h:outputLabel value="To Date" />
                        <p:calendar value="#{storeErrorChecking.toDate}" pattern="dd MM yyyy" placeholder="To Date" ></p:calendar>
                        <h:outputLabel value="Department" />
                        <p:autoComplete value="#{storeErrorChecking.department}"  placeholder="Department"
                                        completeMethod="#{departmentController.completeDept}" var="dept" itemValue="#{dept}" itemLabel="#{dept.name}" 
                                        forceSelection="true" rendered="true" 
                                        requiredMessage="You must select a department" >
                            <p:column headerText="Department">
                                <h:outputLabel value="#{dept.name}"/>
                            </p:column>
                            <p:column headerText="Institution">
                                <h:outputLabel value="#{dept.institution.name}"/>
                            </p:column>
                        </p:autoComplete>
                        <h:outputLabel value="Item" />
                        <p:autoComplete value="#{storeErrorChecking.item}"  placeholder="Item"
                                        completeMethod="#{itemController.completeStoreItem}" 
                                        var="item" itemValue="#{item}" itemLabel="#{item.name}" 
                                        forceSelection="true"  >
                            <p:column headerText="Item">
                                <h:outputLabel value="#{item.name}"/>
                            </p:column>
                            <p:column headerText="Code">
                                <h:outputLabel value="#{item.code}"/>
                            </p:column>
                        </p:autoComplete>
                        <p:commandButton ajax="false" value="List All Bill Items" action="#{storeErrorChecking.listPharmacyMovementByDateRangeOnlyStockChange() }" >
                        </p:commandButton>
                        <p:commandButton ajax="false" value="Print"  styleClass="noPrintButton"    >
                            <p:printer target="panelPrint" />
                        </p:commandButton>
                    </h:panelGrid>

                </f:facet>

                <p:panelGrid columns="2" >



                    <p:panel header="Stock Transaction Hisory" id="panelPrint">

                        <!--                        <h:outputLabel value="Calculated Stock" ></h:outputLabel>
                                                <h:outputLabel value="#{storeErrorChecking.calculatedStock}" ></h:outputLabel>
                                                <br/>-->


                        <p:dataTable styleClass="noBorder summeryBorder" 
                                     value="#{storeErrorChecking.billItems}" var="pb"  rowIndexVar="i"
                                     rowStyleClass="#{(pb.retired eq true or pb.bill.retired eq true) ?'greenText' : ''} 
                                     #{((pb.bill.billClass eq 'class com.divudi.entity.CancelledBill' and pb.bill.billType eq 'StorePurchase' )or
                                       (pb.bill.billClass eq 'class com.divudi.entity.CancelledBill' and pb.bill.billType eq 'StoreGrnBill' )or
                                       (pb.bill.billClass eq 'class com.divudi.entity.BilledBill' and pb.bill.billType eq 'StoreGrnReturn' )or
                                       (pb.bill.billClass eq 'class com.divudi.entity.BilledBill' and pb.bill.billType eq 'StorePurchaseReturn' )or
                                       (pb.bill.billClass eq 'class com.divudi.entity.PreBill' and pb.bill.billType eq 'StorePre' )or
                                       (pb.bill.billClass eq 'class com.divudi.entity.BilledBill' and pb.bill.billType eq 'StoreTransferIssue' )or
                                       (pb.bill.billClass eq 'class com.divudi.entity.CancelledBill' and pb.bill.billType eq 'StoreTransferReceive' )
                                       )? 'redText' : ''}
                                     #{((pb.bill.billClass eq 'class com.divudi.entity.BilledBill' and pb.bill.billType eq 'StorePurchase' and pb.bill.createdAt ne null )or
                                       (pb.bill.billClass eq 'class com.divudi.entity.BilledBill' and pb.bill.billType eq 'StoreGrnBill' and pb.bill.createdAt ne null )or
                                       (pb.bill.billClass eq 'class com.divudi.entity.CancelledBill' and pb.bill.billType eq 'StoreGrnReturn' and pb.bill.createdAt ne null )or
                                       (pb.bill.billClass eq 'class com.divudi.entity.CancelledBill' and pb.bill.billType eq 'StorePurchaseReturn' and pb.bill.createdAt ne null )or
                                       (pb.bill.billClass eq 'class com.divudi.entity.RefundBill' and pb.bill.billType eq 'StorePre' and pb.bill.createdAt ne null )or
                                       (pb.bill.billClass eq 'class com.divudi.entity.CancelledBill' and pb.bill.billType eq 'StoreTransferIssue' and pb.bill.createdAt ne null )or
                                       (pb.bill.billClass eq 'class com.divudi.entity.BilledBill' and pb.bill.billType eq 'StoreTransferReceive' and pb.bill.createdAt ne null )
                                       )? 'greenText' : ''}"
                                     >

                            <f:facet name="header">
                                <p:outputLabel value="#{storeErrorChecking.department.name}" />
                                <br></br>
                                <p:outputLabel value="From - " />
                                <p:outputLabel value="#{storeErrorChecking.fromDate}" >
                                    <f:convertDateTime pattern="yyyy MM dd hh:mm:ss a" />
                                </p:outputLabel>
                                <p:outputLabel value=" - To - " />
                                <p:outputLabel value="#{storeErrorChecking.toDate}" >
                                    <f:convertDateTime pattern="yyyy MM dd hh:mm:ss a" />
                                </p:outputLabel>
                                <br></br>
                                <p:outputLabel value="#{storeErrorChecking.item.name} History" />
                                <br></br>
                            </f:facet>

                            <p:column >
                                <h:outputLabel value="#{i+1}"/>
                            </p:column>
                            <p:column styleClass="noPrintButton" >
                                <p:commandButton action="#{storeBillSearch.viewBill}" value="View Bill">                                    
                                    <f:setPropertyActionListener value="#{pb.bill}" target="#{storeBillSearch.bill}"/>
                                </p:commandButton>
                            </p:column>

                            <p:column headerText="Bill No" >                              
                                <h:panelGrid columns="2">
                                    <h:outputLabel value="Dept Id"/>
                                    <h:outputLabel value="#{pb.bill.deptId}" >
                                    </h:outputLabel>                               
                                    <h:outputLabel value="Ins Id"/>
                                    <h:outputLabel value="#{pb.bill.insId}" >
                                    </h:outputLabel>
                                    <h:outputLabel value="Billed department"/>
                                    <h:outputLabel value="#{pb.bill.department.name}" >
                                    </h:outputLabel>
                                    <h:outputLabel value="To department"/>
                                    <h:outputLabel value="#{pb.bill.toDepartment.name}" >
                                    </h:outputLabel>
                                    <h:outputLabel value="From department"/>
                                    <h:outputLabel value="#{pb.bill.fromDepartment.name}" >
                                    </h:outputLabel>
                                </h:panelGrid>
                            </p:column>

                            <p:column headerText="Stock History" >
                                <h:panelGrid columns="2">
                                    <h:outputLabel value="Stock Id "/>
                                    <h:outputLabel value="#{pb.pharmaceuticalBillItem.stock.id}" >
                                    </h:outputLabel>
                                    <h:outputLabel value="Batch Id "/>
                                    <h:outputLabel value="#{pb.pharmaceuticalBillItem.itemBatch.id}" >
                                    </h:outputLabel>
                                    <h:outputLabel value="Batch No "/>
                                    <h:outputLabel value="#{pb.pharmaceuticalBillItem.itemBatch.batchNo}" >
                                    </h:outputLabel>
                                </h:panelGrid>
                                <h:panelGrid columns="2">                                   
                                    <h:outputLabel value="Before "/>
                                    <h:outputLabel value="#{pb.pharmaceuticalBillItem.stockHistory.stockQty}"  />
                                </h:panelGrid>
                                <h:panelGrid columns="2">
                                    <h:outputLabel value="After "/>
                                    <h:outputLabel value="#{pb.pharmaceuticalBillItem.stockHistory.stockQty+(pb.pharmaceuticalBillItem.qtyInUnit+pb.pharmaceuticalBillItem.freeQtyInUnit)}"
                                                   />

                                </h:panelGrid>
                            </p:column>

                            <p:column headerText="Qty" >
                                <h:panelGrid columns="2">
                                    <h:outputLabel value="Bill Qty"/>
                                    <h:outputLabel value="#{pb.qty}" >
                                    </h:outputLabel>
                                    <h:outputLabel value="Ph Qty"/>
                                    <h:outputLabel value="#{pb.pharmaceuticalBillItem.qtyInUnit}" >
                                    </h:outputLabel>
                                    <h:outputLabel value="Ph Free Qty"/>
                                    <h:outputLabel value="#{pb.pharmaceuticalBillItem.freeQtyInUnit}" >
                                    </h:outputLabel>
                                </h:panelGrid>

                            </p:column>

                            <p:column headerText="Bill Item Detail" >
                                <h:panelGrid columns="2">
                                    <h:outputLabel value="Billed Date"/>
                                    <h:outputLabel value="#{pb.createdAt}" >
                                        <f:convertDateTime pattern="dd MMM yyyy HH:mm:ss a" ></f:convertDateTime>
                                    </h:outputLabel>
                                    <h:outputLabel value="Retired"/>
                                    <h:outputLabel value="#{pb.retired}" >
                                    </h:outputLabel>
                                    <h:outputLabel value="BillType"/>
                                    <h:outputLabel value="#{pb.bill.billType}" >
                                    </h:outputLabel>
                                    <h:outputLabel value="Bill Class"/>
                                    <h:outputLabel value="#{pb.bill.billClass}" >
                                    </h:outputLabel>
                                </h:panelGrid>
                            </p:column>

                        </p:dataTable>


                    </p:panel>


                </p:panelGrid>







            </p:panel>




        </h:form>



    </ui:define>

</ui:composition>
